package com.cjm.algorithm.dfs;

public class Ti417 {
    /**
     * dp[j] = max(dp[j], dp[j-weight(i)]+value[i]
     * @param args
     */
    public static void main(String[] args) {

    }

    public boolean canPartition(int[] nums) {
        int sum = 0;
        // dp[i] 表示背包内元素的总和
        int[] dp = new  int[10001];
        for (int num : nums) {
            sum+=num;
        }
        // 也就是除不开
        if (sum % 2 == 1) return false;

        int target = sum / 2;

        for (int i = 0; i < nums.length; i++) {
            for (int j = target; j >= nums[i]; j++) {
                dp[j] = Math.max(dp[j], dp[j - nums[i]] + nums[i]);
            }
        }

        if (dp[target] == target) return true;

        return false;
    }
}
